﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/HomeSite.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<TimeTableManagement.Controllers.RegSlot>>" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>

<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">


    <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" Width="100%" 
        CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" 
        GroupBoxCaptionOffsetY="-28px" 
        SpriteCssFilePath="~/App_Themes/Aqua/{0}/sprite.css">
        <ContentPaddings Padding="14px" />
        <PanelCollection>
<dx:PanelContent ID="PanelContent1" runat="server" SupportsDisabledAttribute="True">
<% using (Html.BeginForm())
   { %>
    <%: Html.ValidationSummary(true)%>
<table style="width:100%" id="t1" class="example table-autosort
 table-autofilter table-autopage:10 
 table-stripeclass:alternate 
 table-page-number:t1page table-page-count:t1pages 
 table-filtered-rowcount:t1filtercount 
 table-rowcount:t1allcount">
 <thead>
    <tr>
        <th class="tablecell">
            Slot
        </th>
        <th class="tablecell">
            From
        </th>
        <th class="tablecell">
            To
        </th>
        <th>
        <input type="checkbox" onclick="SelectAllCheckbox(this)">Tất cả</input>
        </th>
    </tr>
    </thead>
    <tbody>
    <%
       TimeTableManagement.QLSVContext db = new TimeTableManagement.QLSVContext();
       var list = db.Tb_Slot.ToList();
        %>
<% foreach (var item in list)
   { %>
       <tr>
        <td class="tablecell">
            <%: Html.DisplayFor(modelItem => item.slot)%>
        </td>
        <td class="tablecell">
            <%: TimeTableManagement.Entities.Tb_Slot.getFrom(item.from)%>
        </td>
        <td class="tablecell">
            <%: TimeTableManagement.Entities.Tb_Slot.getFrom(item.to)%>
        </td>
        <% bool k= false;
           foreach (var iitem in Model)
           {
               if (iitem.id == item.id) { k = true; break; }
           } %>
        <td>
        <% if (k)
           { %>
            <input id="<%: item.id %>" slot="<%: item.slot %>" type="checkbox" class="slotcollection" checked=checked/>
            <% }
           else
           { %>
            <input id="<%: item.id %>" slot="<%: item.slot %>" type="checkbox" class="slotcollection"/>
            <% } %>
        </td>
    </tr>
<% } %>
</tbody>
<tfoot>
	<tr>
		<td class="table-page:previous" style="cursor:pointer; text-align:right"><img src="../../Content/iconprevious.png" /></td>
		<td style="text-align:center" colspan="2" class="table-page-number:t1page">Page <span id="t1page"></span>&nbsp;of&nbsp;<span id="t1pages"></span></td>
        <td class="table-page:next" style="cursor:pointer; text-align:left"> <img src="../../Content/iconnext.png" /></td>
	</tr>
</tfoot>
</table>
    <input id="regslot" name="regslot" type="hidden" value='' />
<%--    Tao chuoi json cho regslot theo cau truc
     [{"id":id_slot,"slot":"name_slot","prior":uu_tien}]--%>
   <p>
       
     <input type="submit" value="Create" onclick="return updatejson()"/>
   </p>
<% } %>
</dx:PanelContent>
</PanelCollection>
    </dx:ASPxRoundPanel>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
<script>
    function updatejson() {
        $json = "";
        $prior = 0;
        $items = document.getElementsByClassName('slotcollection');
        for ($i = 0; $i < $items.length; $i++) {
            $item = $items.item($i);
            if ($item.checked == true) {
                $id = $item.id;
                $prior++;
                $slot = $item.getAttribute('slot');
                $json = $json + ',{"id":' + $id + ',"slot":"' + $slot + '","prior":' + $prior + '}';
            }
        }
        $json = '[' + $json.substr(1) + ']';
        document.getElementById('regslot').value = $json;
        return true;
    }
</script>
<script type="text/javascript">
    function SelectAllCheckbox(e) {
        $value = e.checked;
        $items = document.getElementsByClassName('slotcollection');
        for ($i = 0; $i < $items.length; $i++) {
            $items.item($i).checked = $value;
        }
    }
</script>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="leftmenu" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="menuright" runat="server">
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="Footer" runat="server">
</asp:Content>
